<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Sys_usr_info extends CI_Model {

    var $table_name = "sys_usr_info";

    function __construct() {
        parent::__construct();
    }
    

    function get_user($email, $password) {
	$email = $this->db->escape_str(trim(strtolower($email)));
        $this->db->where("email", $email);
	$this->db->where("password",  md5($password + substr($email,0,4) + PASSWORD_HASH));
	$query = $this->db->get($this->table_name);
	$result = $query->result();
	if ($result) 
		return $result[0];
	else
		return false;
    }

/*
    function login_update($uid) {
		$this->db->where("uid", $uid);
		$this->db->set("logtimes","logtimes+1",FALSE);
		$this->db->set("lastlogtime", time());
		$this->db->update($this->table_name);
    }
*/

    function create_user($email, $password, $nickname)
    {
        $email      = $this->db->escape_str(trim(strtolower($email)));
        
        $this->db->where("email",$email);
        $query = $this->db->get($this->table_name);
	$result = $query->result();
        if ($result)
            return false;
        else
        {
           $password   = trim($password);
            $nickname   = trim($nickname);
            if ($nickname == "") $nickname = $email;
	    if ($email && $password)
	    {
		$data = array(
		   'email' => $email,
		   'password' => md5($password + substr($email,0,4) + PASSWORD_HASH), 
		   'nickname' => $nickname,
		   'regtime' => time()
		);
    
		$this->db->insert($this->table_name, $data);
		return true;
	    }
	    else return false;
        }
        
    }
}

?>